package com.tool;

/**
 * Created by tjpu on 2016/10/12.
 */
public class Coordinate {
    public double x;   //直角坐标系,正前方X为正
    public double y;    //直角坐标系，左侧Y为正
    double length;

    public Coordinate() {
        this.x = 0;
        this.y = 0;
        length = Math.sqrt(x * x + y * y);
    }

    public Coordinate(double x, double y) {
        this.x = x;
        this.y = y;
        length = Math.sqrt(x * x + y * y);
    }

    public double getLength() {
        return length = Math.sqrt(x * x + y * y);
    }

    public static double[]  rotation(double x, double y, double angle) {
        double [] newPoint = new double[2];

        newPoint[0] = Math.cos(angle) * x - Math.sin(angle) * y;
        newPoint[1] = Math.sin(angle) * x + Math.cos(angle) * y;
        return newPoint;
    }

    public void rotation(double angle) {
        double [] newPoint = new double[2];

        newPoint[0] = Math.cos(angle) * x - Math.sin(angle) * y;
        newPoint[1] = Math.sin(angle) * x + Math.cos(angle) * y;
        x = newPoint[0];
        y = newPoint[1];
    }
}
